import {useUserStore} from '@/pinia/user.js'
const user = useUserStore()
export const loginBefore = (e = {}) => {
	const {inviteCode = ''} = e
	// console.log("login",user.hasLogin)
	uni.login({
		provider: 'weixin',
		onlyAuthorize: true,
		success: async res => {
			console.log("res", res)
			await login({
				code: res.code,
				inviteCode,
			})
		},
		fail: (err) => {
			console.log(err);
		},
		complete: () => {}
	});
};
const login = async (params) => { //联网验证登录
	const uniIdCo = uniCloud.importObject("uni-id-co", {
		customUI: true
	})
	uniIdCo.loginByWeixin(params)
		.then(result => {
			user.loginSuccess()
		})
		.catch(e => {
			
		})
		.finally(e => {
			
		})
}
